package com.igeekhome.ccs.controller;

import com.igeekhome.ccs.biz.ICustomerServiceBiz;
import com.igeekhome.ccs.biz.ICustomerServiceGroupBiz;
import com.igeekhome.ccs.biz.ICustomerServiceRoleBiz;
import com.igeekhome.ccs.entity.CustomerService;
import com.igeekhome.ccs.entity.CustomerServiceGroup;
import com.igeekhome.ccs.entity.CustomerServiceRole;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/csrole")
public class CustomerServiceRoleController {
    @Autowired
    private ICustomerServiceRoleBiz biz;
    @Autowired
    private ICustomerServiceBiz iCustomerServiceBiz;
//👇zyh---------------------------------------------------------------------------

    /**
     * 对外提供查询角色表所有信息
     */
    @GetMapping("/query")
    public @ResponseBody
    List<CustomerServiceRole> query() {
        return  biz.query();
    }

    /**
     * 传入搜索字符串返回角色对象
     */
    @GetMapping("/queryCsrByString")
    public @ResponseBody
    List<CustomerServiceRole> queryCsrByString(@RequestBody Map<String, String> map) {
        return biz.matchCsrwithString(map.get("trs"));
    }

    /**
     * 传入id返回对应角色信息
     */
    @GetMapping("/queryCsrById")
    public @ResponseBody
    CustomerServiceRole queryCsrById(@RequestBody Map<String, String> map) {
        return biz.queryCsrById(Integer.parseInt(map.get("csrId")));
    }

    /**
     * 传入id删除单个角色
     */
    @DeleteMapping("/deleteCsrById")
    public  @ResponseBody
    void deleteCsrById(@RequestBody Map<String, String> map){
        biz.deleteCsrById(Integer.parseInt(map.get("csrId")));
    }

    /**
     * 传入list(id)批量删除角色
     */
    @DeleteMapping("/deleteCsrByList")
    public @ResponseBody
    void deleteCsrByList(List<Integer> list){
        biz.deleteCsrByList(list);
    }

    /**
     * 新增角色
     */
    @PostMapping("/createNewCsr")
    public  @ResponseBody
    void createNewCsr(@RequestBody CustomerServiceRole customerServiceRole) throws ParseException {
        CustomerService cs=iCustomerServiceBiz.getOneByUsername((String) SecurityUtils.getSubject().getPrincipal());
        biz.createNewCsr(customerServiceRole,cs.getCsId());
    }

    /**
     * 编辑角色
     */
    @PostMapping("/updateCsr")
    public @ResponseBody
    int updateCsr(@RequestBody Map<String, String> map) throws ParseException {
        biz.updateCsr(map.get("newRoleName"),map.get("newRoleDesc"),Integer.parseInt(map.get("newP1")),Integer.parseInt(map.get("newP2")),Integer.parseInt(map.get("csrId")));
        return 0;
    }

//👆zyh---------------------------------------------------------------------------
}
